package com.jt.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.jt.dubbo.pojo.User;
import com.jt.dubbo.service.UserService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class UserController {

    @Reference(check = false)
    private UserService userService;

    @RequestMapping("findObjects")
    public List<User> findObject() {
        return userService.findObjects();
    }

    @RequestMapping("findUserById/{userId}")
    public User findUserById(@PathVariable Long userId) {
        return userService.findUserById(userId);
    }

    @RequestMapping("saveObject/{name}/{age}/{sex}")
    public String saveObject(User user) {
        userService.saveObject(user);
        return "save ok";
    }

    @RequestMapping("deleteById/{userId}")
    public String deleteById(@PathVariable Long userId) {
        userService.deleteById(userId);
        return "delete ok";
    }

    @RequestMapping("updateObject/{id}/{name}/{age}/{sex}")
    public String updateObject(User user) {
        userService.updateObject(user);
        return "update ok";
    }
}
